package com.example.sociamedia.interaction.mapper;

import com.example.sociamedia.interaction.entity.Follow;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface FollowMapper {
    @Insert("INSERT INTO userfollows (FollowerId, FollowingId, CreatedAt) VALUES (#{followerId}, #{followingId}, NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "followId", keyColumn = "FollowId")
    int insertFollow(Follow follow);

    @Delete("DELETE FROM userfollows WHERE FollowerId = #{followerId} AND FollowingId = #{followingId}")
    int deleteFollow(@Param("followerId") Long followerId, @Param("followingId") Long followingId);

    @Select("SELECT * FROM userfollows WHERE FollowerId = #{followerId} AND FollowingId = #{followingId}")
    Follow selectFollow(@Param("followerId") Long followerId, @Param("followingId") Long followingId);

    @Select("SELECT * FROM userfollows WHERE FollowerId = #{followerId}")
    List<Follow> selectFollowings(@Param("followerId") Long followerId);

    @Select("SELECT * FROM userfollows WHERE FollowingId = #{followingId}")
    List<Follow> selectFollowers(@Param("followingId") Long followingId);
} 